
#include "S_27_AiContrrol_doSet.h"
#include "string.h"
#include "mi_iid_define.h"
#include "spec.h"
#include "main.h"
#include "section1_set_func.h"

static void P_27_1_AiCompressorFreq_doSet(property_operation_t *o)
{
	char *Temp = NULL;
	char *Buf[5] = {0};
	short Data[2] = {0};
	char FanLevel[2] = {0};
	short state = 0;
	uint8_t Cnt = 0;	
	
    // 判断数据格式是否正确，如果错误，返回代码: OPERATION_ERROR_VALUE
    if (o->value.format != PROPERTY_FORMAT_STRING)
    {
        o->code = OPERATION_ERROR_VALUE;
        return;
    }

    // TODO: 执行写操作: o->value.data.string.value;

	LOG_INFO("%s, %s\r\n",__func__,o->value.data.string.value);
	
    // 如果成功，返回代码: OPERATION_OK
    o->code = OPERATION_OK;
		
	Temp = strtok(o->value.data.string.value,","); 
	while((Temp != NULL) && (Cnt < 5)) 
	{
		Buf[Cnt] = Temp;
		Cnt ++;
		Temp = strtok(NULL, ",");
	}
	state = atoi(Buf[0]) + 100;
	Data[0] = atoi(Buf[1]) + 1000;
	Data[1] = atoi(Buf[2]) +1000;
	FanLevel[0] = atoi(Buf[3])+100;
	FanLevel[1] = atoi(Buf[4]) + 100;
	
	PRINTF("27_1:%d %d %d %d %d\r\n",state,Data[0],Data[1],FanLevel[0],FanLevel[1]);
	
	
//	if((-2 == state) || (1 == state))
	{
		A44_27_1_Set(state,Data[0],Data[1],FanLevel[0],FanLevel[1]);
//		BeepStart();
	}
	
	g_BeepInvalidFlag = 1;
//	A44_27_1_Set();
    return;
}

//static void P_27_2_AiParam_doSet(property_operation_t *o)
//{
//    // 判断数据格式是否正确，如果错误，返回代码: OPERATION_ERROR_VALUE
//    if (o->value.format != PROPERTY_FORMAT_STRING)
//    {
//        o->code = OPERATION_ERROR_VALUE;
//        return;
//    }

//    // TODO: 执行写操作: o->value.data.string.value;

//    // 如果成功，返回代码: OPERATION_OK
//    o->code = OPERATION_OK;
//    
//    //上报状态，通知app状态变化，统一APP修改、定时器触发后的上报机制
////    P_27_2_AiParam_doChange_notify(o->value.data.string.value);

//    return;
//}

void S_27_AiContrrol_doSet(property_operation_t *o)
{
    switch (o->piid)
    {
        case PIID_27_1_AiCompressorFreq:
            P_27_1_AiCompressorFreq_doSet(o);
            break;

//        case PIID_27_2_AiParam:
//            P_27_2_AiParam_doSet(o);
//            break;

        default:
            o->code = OPERATION_ERROR_VALUE;
            break;
    }
}
